import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 导航传递参数到父页面
 */
class MyApp16 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "BottomNavigationWidget",
      home: BottomNavigationWidget(),
    );
  }
}

class BottomNavigationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return BottomNavigationWidgetState();
  }
}

class BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  int currentIndex = 0;

  List<Widget> list = List();
  @override
  void initState() {
    list.add(HomePage());
    list.add(EmailPage());
    list.add(PagesPage());
    list.add(AirplanPage());
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: list[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.home,
                color: Colors.green,
              ),
              title: Text("HOME")),
          BottomNavigationBarItem(
              icon: Icon(Icons.email, color: Colors.green),
              title: Text("EMAIL")),
          BottomNavigationBarItem(
              icon: Icon(Icons.pages, color: Colors.green),
              title: Text("PAGES")),
          BottomNavigationBarItem(
              icon: Icon(Icons.airplay, color: Colors.green),
              title: Text("AIRPLAN"))
        ],
        currentIndex: currentIndex,
        onTap: (int index) {
          setState(() {
            currentIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("HomePage"),),
      body: Center(
        child: Text("HomePage"),
      ),
    );
  }
}

class EmailPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(title: Text("EmailPage"),),
        body: Center(
          child: Text("EmailPage"),
        ),
      );
  }
}

class PagesPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("PagesPage"),),
      body: Center(
        child: Text("PagesPage"),
      ),
    );
  }
}
class AirplanPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("AIRPLAN"),),
      body: Center(
        child: Text("AIRPLAN"),
      ),
    );
  }
}
